home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games: Greatest Hits 1996 / Amiga Games: Greatest Hits 1996.iso / archive / userbox / publicdomain / fractal.lha / fractal / source_amiga / dec.c next >
C/C++ Source or Header  |  1996-07-02  |  22KB  |  584 lines

  1. /**************************************************************************/
  2. /* Decode an image encoded with a quadtree partition based fractal scheme */
  3. /*                                                                        */
  4. /*       Copyright 1993,1994 Yuval Fisher. All rights reserved.           */
  5. /*                                                                        */
  6. /* Version 0.05 10/10/94                                                  */
  7. /**************************************************************************/
  8.  
  9. /* see CHANGES.AMIGA for which changes done for the Amiga port
  10.    by Andreas R. Kleinert
  11.  
  12.    V1.0: 02-July-96
  13. */
  14.  
  15.  
  16. /* The following belong in a encdec.h file, but nevermind...              */
  17. /* -----------------------------------------------------------------------*/
  18. #include <stdio.h>
  19. #include <math.h>
  20.  
  21. /* added by ak */
  22. #include <string.h>
  23. #include <stdlib.h>
  24. #include <m68881.h>
  25. /* eo - added by ak */
  26.  
  27. #define DEBUG 0
  28. #define GREY_LEVELS 255
  29.  
  30. #define IMAGE_TYPE unsigned char /* may be different in some applications */
  31.  
  32. /* The following #define allocates an hsize x vsize  matrix of type type */
  33. #define matrix_allocate(matrix, hsize,vsize, TYPE) {\
  34.     TYPE *imptr; \
  35.     int _i; \
  36.     matrix = (TYPE **)malloc(vsize*sizeof(TYPE *));\
  37.     imptr = (TYPE*)malloc((long)hsize*(long)vsize*sizeof(TYPE));\
  38.     if (imptr == NULL) \
  39.         fatal("\nNo memory in matrix allocate."); \
  40.     for (_i = 0; _i<vsize; ++_i, imptr += hsize) \
  41.         matrix[_i] = imptr; \
  42.  }
  43.  
  44. #define bound(a)   ((a) < 0.0 ? 0 : ((a)>255.0? 255 : a))
  45.  
  46. #ifdef EXCLUDED_AK
  47. /* various function declarations to keep compiler warnings away           */
  48. void fatal();
  49. char *malloc();
  50. char *strcpy(); 
  51. #endif /* EXCLUDED_AK */
  52.  
  53. /* ---------------------------------------------------------------------- */
  54.  
  55. IMAGE_TYPE **image,*imptr,**image1; 
  56.                              /* The input image data and a dummy         */ 
  57.  
  58. double max_scale = 1.0;      /* maximum allowable grey level scale factor */
  59.  
  60. int    s_bits = 5,           /* number of bits used to store scale factor */
  61.        o_bits = 7,           /* number of bits used to store offset       */
  62.        hsize = -1,           /* The horizontal size of the input image    */
  63.        vsize = -1,           /* The vertical size                         */
  64.        scaledhsize,          /* hsize*scalefactor                         */
  65.        scaledvsize,          /* vsize*scalefactor                         */
  66.        size,                 /* largest square image that fits in image   */
  67.        min_part = 3,         /* min and max _part determine a range of    */
  68.        max_part = 4,         /* Range sizes from hsize>>min to hsize>>max */
  69.        dom_step = 4,         /* Density of domains relative to size       */
  70.        dom_step_type = 0,    /* Flag for dom_step a multiplier or divisor */
  71.        dom_type = 0,         /* Method of generating domain pool 0,1,2..  */
  72.        post_process = 1,     /* Flag for postprocessing.                  */
  73.        num_iterations= 10,   /* Number of decoding iterations used.       */
  74.        *no_h_domains,        /* Number of horizontal domains.             */
  75.        *domain_hstep,        /* Domain density step size.                 */
  76.        *domain_vstep,        /* Domain density step size.                 */
  77.        *bits_needed,         /* Number of bits to encode domain position. */
  78.        zero_ialpha,          /* the const ialpha when alpha = 0           */
  79.        output_partition=0,   /* A flag for outputing the partition        */
  80.        max_exponent;         /* The max power of 2 side of square image   */
  81.                              /* that fits in our input image.             */
  82.  
  83. struct transformation_node {
  84.        int rx,ry,            /* The range position and size in a trans.   */
  85.               xsize, ysize,  
  86.               rrx,rry,
  87.               dx,dy;         /* The domain position.                      */
  88.        int sym_op;           /* The symmetry operation used in the trans. */
  89.        int depth;            /* The depth in the quadtree partition.      */
  90.        double scale, offset; /* scalling and offset values.               */
  91.        struct transformation_node *next;       /* The next trans. in list */
  92. } transformations, *trans; 
  93.  
  94. FILE *input,*output,*other_input; 
  95.  
  96.  
  97. /* fatal is for when there is a fatal error... print a message and exit */
  98. void fatal(s)
  99. char *s;
  100. {
  101.      printf("\n%s\n",s);
  102.      exit(-1);
  103. }
  104.  
  105. /* ************************************************************ */
  106. /* unpack value using size bits read from fin.                  */
  107. /* ************************************************************ */
  108. long unpack(size, fin)
  109. int size;
  110. FILE *fin;
  111. {
  112.     int i;
  113.     int value = 0;
  114.     static int ptr = 1; /* how many bits are packed in sum so far */
  115.     static int sum; 
  116.  
  117.  
  118.     /* size == -2 means we initialize things */
  119.     if (size == -2) {
  120.         sum = fgetc(fin);
  121.         sum <<= 1;
  122.         return((long)0);
  123.     }
  124.  
  125.     /* size == -1 means we want to peek at the next bit without */
  126.     /* advancing the pointer */
  127.     if (size == -1)
  128.         return((long)((sum&256)>>8));
  129.  
  130.      for (i=0; i<size; ++i, ++ptr,  sum <<= 1) {
  131.         if (sum & 256) value |= 1<<i;
  132.  
  133.          if (ptr == 8) {
  134.             sum = getc(fin);
  135.             ptr=0;
  136.         }
  137.      }
  138.     return((long)value);
  139. }
  140.  
  141. main(argc,argv)
  142. int argc;
  143. char **argv;
  144. {
  145.     /* Defaults are set initially */
  146.     double         scalefactor = 1.0;           /* Scale factor for output */
  147.     char           inputfilename[200];
  148.     char           outputfilename[200];
  149.     char           other_input_file[200];
  150.     int            i,j, x_exponent, y_exponent;
  151.     int            domain_size, no_domains;
  152.  
  153.  
  154.     inputfilename[0] = 1;    /* We initially set the input to this and */
  155.     outputfilename[0] = 1;   /* then check if the input/output names   */
  156.     other_input_file[0] = 1; /* have been set below.                   */
  157.  
  158.     /* scan through the input line and read in the arguments */
  159.     for (i=1; i<argc; ++i) 
  160.        if (argv[i][0] != '-' ) 
  161.             if (inputfilename[0] == 1)
  162.                 strcpy(inputfilename, argv[i]);
  163.             else if (outputfilename[0] == 1)
  164.                 strcpy(outputfilename, argv[i]);
  165.             else;
  166.        else { /* we have a flag */
  167.             if (strlen(argv[i]) == 1) break;
  168.             switch(argv[i][1]) {
  169.                case 'i': strcpy(other_input_file,argv[++i]); 
  170.                          break;
  171.                case 'n': num_iterations = atoi(argv[++i]);
  172.                          break;
  173.                case 'f': scalefactor = atof(argv[++i]);
  174.                          break;
  175.                case 'P': output_partition = 1;
  176.                          break;
  177.                case 'p': post_process = 0;
  178.                          break;
  179.                case 's': s_bits = atoi(argv[++i]);
  180.                          break;
  181.                case 'o': o_bits = atoi(argv[++i]);
  182.                          break;
  183.                case 'N': max_scale = atof(argv[++i]);
  184.                          break;
  185.                case '?':
  186.                case 'H':
  187.                default:
  188.            printf("\nUsage: dec -[options] [inputfile [outputfile]]");
  189.            printf("\nOptions are: (# = number), defaults show in ()");
  190.            printf("\n  -f # scale factor of output size. (%lf)", scalefactor);
  191.            printf("\n  -i file name. An initial image to iteration from.");
  192.            printf("\n  -n # no. of decoding iterations. (%d)", num_iterations);
  193.            printf("\n  -N # maximum allowed scaling. (%lf)",max_scale);
  194.            printf("\n  -s # number of scaling quantizing bits. (%d)",s_bits);
  195.            printf("\n  -o # number of offset quantizing bits. (%d)",o_bits);
  196.            printf("\n  -P   output the partition into the output file. (off)");
  197.            printf("\n  -p   supress artifact postprocessing. (off)");
  198.            fatal(" ");
  199.             }
  200.        }
  201.  
  202.     if (inputfilename[0] == 1) strcpy(inputfilename, "lenna.trn");
  203.     if (outputfilename[0] == 1) strcpy(outputfilename, "lenna.out");
  204.  
  205.     if ((input = fopen(inputfilename, "r")) == NULL)
  206.         fatal("Can't open input file.");
  207.         
  208.     unpack(-2,input); /* initialize the unpacking routine */
  209.  
  210.     /* read the header data from the input file. This should probably */
  211.     /* be put into one read which reads a structure with the info     */
  212.     min_part = (int)unpack(4,input);
  213.     max_part = (int)unpack(4,input);
  214.     dom_step = (int)unpack(4,input);
  215.     dom_step_type = (int)unpack(1,input);
  216.     dom_type = (int)unpack(2,input);
  217.     hsize = (int)unpack(12,input);
  218.     vsize = (int)unpack(12,input);
  219.  
  220.     /* we now compute size */
  221.     x_exponent = (int)floor(log((double)hsize)/log(2.0));
  222.     y_exponent = (int)floor(log((double)vsize)/log(2.0));
  223.    
  224.     /* exponent is min of x_ and y_ exponent */
  225.     max_exponent = (x_exponent > y_exponent ? y_exponent : x_exponent);
  226.     /* size is the size of the largest square that fits in the image */
  227.     /* It is used to compute the domain and range sizes.             */
  228.     size =  1<<max_exponent; 
  229.  
  230.     /* This is the quantized value of zero scaling */
  231.     zero_ialpha = 0.5 + (max_scale)/(2.0*max_scale)*(1<<s_bits);
  232.  
  233.     /* allocate memory for the output image. Allocating one chunck saves  */
  234.     /* work and time later.                                              */
  235.     scaledhsize = (int)(scalefactor*hsize);
  236.     scaledvsize = (int)(scalefactor*vsize);
  237.     matrix_allocate(image, scaledhsize,scaledvsize, IMAGE_TYPE);
  238.     matrix_allocate(image1, scaledhsize, scaledvsize, IMAGE_TYPE);
  239.  
  240.     if (other_input_file[0] != 1) {
  241.         other_input = fopen(other_input_file, "r");
  242.         i = fread(image[0], sizeof(IMAGE_TYPE), 
  243.                 scaledhsize*scaledvsize, other_input);
  244.         if (i < scaledhsize*scaledvsize) 
  245.            fatal("Couldn't read input... not enough data.");
  246.         else
  247.             printf("\n%d pixels read from %s.\n", i,other_input_file);
  248.         fclose(other_input);
  249.     }
  250.           
  251.     /* since max_ and min_ part are variable, these must be allocated */
  252.     i = max_part - min_part + 1;
  253.     bits_needed = (int *)malloc(sizeof(int)*i);
  254.     no_h_domains = (int *)malloc(sizeof(int)*i);
  255.     domain_hstep = (int *)malloc(sizeof(int)*i);
  256.     domain_vstep = (int *)malloc(sizeof(int)*i);
  257.     
  258.     /* compute bits needed to read each domain type */
  259.     for (i=0; i <= max_part-min_part; ++i) {
  260.        /* first compute how many domains there are horizontally */
  261.        domain_size = size >> (min_part+i-1);
  262.        if (dom_type == 2) 
  263.              domain_hstep[i] = dom_step; 
  264.        else if (dom_type == 1)
  265.              if (dom_step_type ==1)
  266.                 domain_hstep[i] = (size >> (max_part - i-1))*dom_step;
  267.              else 
  268.                 domain_hstep[i] = (size >> (max_part - i-1))/dom_step;
  269.        else 
  270.              if (dom_step_type ==1)
  271.                 domain_hstep[i] = domain_size*dom_step;
  272.              else 
  273.                 domain_hstep[i] = domain_size/dom_step;
  274.  
  275.        no_h_domains[i] = 1+(hsize-domain_size)/domain_hstep[i];
  276.        /* bits_needed[i][0] = ceil(log(no_domains)/log(2));  */
  277.  
  278.        /* now compute how many domains there are vertically */
  279.        if (dom_type == 2) 
  280.              domain_vstep[i] = dom_step; 
  281.        else if (dom_type == 1)
  282.              if (dom_step_type ==1)
  283.              domain_vstep[i] = (size >> (max_part - i-1))*dom_step;
  284.              else 
  285.              domain_vstep[i] = (size >> (max_part - i-1))/dom_step;
  286.        else 
  287.              if (dom_step_type ==1)
  288.                 domain_vstep[i] = domain_size*dom_step;
  289.              else 
  290.                 domain_vstep[i] = domain_size/dom_step;
  291.  
  292.        no_domains = 1+(vsize-domain_size)/domain_vstep[i];
  293.        bits_needed[i] = ceil(log((double)no_domains*(double)no_h_domains[i])/
  294.                            log(2.0)); 
  295.      }
  296.  
  297.     if ((output = fopen(outputfilename, "w")) == NULL)
  298.             fatal("Can't open output file.");
  299.  
  300.     /* Read in the transformation data */
  301.     trans = &transformations;
  302.     printf("\nReading transformations.....");
  303.     fflush(stdout);
  304.     partition_image(0, 0, hsize,vsize );
  305.     fclose(input);
  306.     printf("Done.");
  307.     fflush(stdout);
  308.    
  309.     if (scalefactor != 1.0) {
  310.         printf("\nScaling image to %d x %d.", scaledhsize,scaledvsize);
  311.         scale_transformations(scalefactor); 
  312.     }
  313.  
  314.     /* when we output the partition, we just read the transformations */
  315.     /* in and write them to the outputfile                            */ 
  316.     if (output_partition) {
  317.           fprintf(output,"\n%d %d\n %d %d\n%d %d\n\n", 
  318.                   0, 0, scaledhsize, 0, scaledhsize, scaledvsize);
  319.           printf("\nOutputed partition data in %s\n",outputfilename);
  320.           fclose(output);
  321.           return;
  322.     }
  323.  
  324.     for (i=0; i<num_iterations; ++i) 
  325.       apply_transformations();
  326.  
  327.     if (post_process)     
  328.       smooth_image();
  329.  
  330.     i = fwrite(image[0], sizeof(IMAGE_TYPE), scaledhsize*scaledvsize, output);
  331.     if (i < scaledhsize*scaledvsize) 
  332.         fatal("Couldn't write output... not enough disk space ?.");
  333.     else
  334.         printf("\n%d pixels written to output file.\n", i);
  335.  
  336.     fclose(output);
  337. }
  338.  
  339. /* ************************************************************ */
  340. /* Read in the transformation data from *input.                 */
  341. /* This is a recursive routine whose recursion tree follows the */
  342. /* recursion done by the encoding program.                      */
  343. /* ************************************************************ */
  344. read_transformations(atx,aty,xsize,ysize,depth)
  345. int atx,aty,xsize,ysize,depth; 
  346. {
  347.     /* Having all these locals in a recursive procedure is hard on the  */
  348.     /* stack.. but it is more readable.                                 */
  349.     int i,j,
  350.         sym_op,                   /* A symmetry operation of the square */
  351.         ialpha,                   /* Intgerized scalling factor         */
  352.         ibeta;                    /* Intgerized offset                  */
  353.  
  354.     long domain_ref; 
  355.  
  356.     double alpha, beta;
  357.  
  358.     /* keep breaking it down until we are small enough */
  359.     if (depth < min_part) {
  360.          read_transformations(atx,aty, xsize/2, ysize/2, depth+1);
  361.          read_transformations(atx+xsize/2,aty, xsize/2, ysize/2, depth+1);
  362.          read_transformations(atx,aty+ysize/2,xsize/2, ysize/2,  depth+1);
  363.          read_transformations(atx+xsize/2,aty+ysize/2,xsize/2,ysize/2,depth+1);
  364.          return;
  365.     }
  366.  
  367.     if (depth < max_part && unpack(1,input)) {
  368.          /* A 1 means we subdivided.. so quadtree */
  369.          read_transformations(atx,aty, xsize/2, ysize/2, depth+1);
  370.          read_transformations(atx+xsize/2,aty, xsize/2, ysize/2, depth+1);
  371.          read_transformations(atx,aty+ysize/2, xsize/2, ysize/2, depth+1);
  372.          read_transformations(atx+xsize/2,aty+ysize/2,xsize/2,ysize/2,depth+1);
  373.     } else {  
  374.          /* we have a transformation to read */
  375.          trans->next = (struct transformation_node *)
  376.                   malloc(sizeof(struct transformation_node ));
  377.          trans = trans->next; trans->next = NULL;
  378.          ialpha = (int)unpack(s_bits,  input);
  379.          ibeta = (int)unpack(o_bits,  input);
  380.          alpha = (double)ialpha/(double)(1<<s_bits)*(2.0*max_scale)-max_scale;
  381.  
  382.          beta = (double)ibeta/(double)((1<<o_bits)-1)*
  383.                ((1.0+fabs(alpha))*GREY_LEVELS);
  384.          if (alpha > 0.0) beta -= alpha*GREY_LEVELS;
  385.  
  386.          trans->scale = alpha;
  387.          trans->offset = beta;
  388.          if (ialpha != zero_ialpha) {
  389.             trans-> sym_op = (int)unpack(3, input);
  390.             domain_ref = unpack(bits_needed[depth-min_part], input);
  391.             trans->dx = (double)(domain_ref % no_h_domains[depth-min_part])
  392.                                               * domain_hstep[depth-min_part];
  393.             trans->dy = (double)(domain_ref / no_h_domains[depth-min_part])
  394.                                               * domain_vstep[depth-min_part];
  395.          } else {
  396.             trans-> sym_op = 0;
  397.             trans-> dx  = 0;
  398.             trans-> dy = 0;
  399.          }
  400.          trans->rx = atx;
  401.          trans->ry = aty;
  402.          trans->depth = depth;
  403.         
  404.          trans->rrx = atx + xsize;
  405.          trans->rry = aty + ysize;
  406.  
  407.          if (output_partition) 
  408.                 fprintf(output,"\n%d %d\n %d %d\n%d %d\n\n", 
  409.                   atx,       vsize-aty-ysize, 
  410.                   atx,       vsize-aty, 
  411.                   atx+xsize, vsize-aty);
  412.   
  413.     }
  414. }
  415.      
  416. /* ************************************************************ */
  417. /* Apply the transformations once to an initially black image.  */
  418. /* ************************************************************ */
  419. apply_transformations()
  420. {
  421.     IMAGE_TYPE **tempimage;
  422.     int    i,j,i1,j1,count=0;
  423.     double pixel;
  424.  
  425.     trans = &transformations;
  426.     while (trans->next != NULL) {
  427.         trans = trans->next;
  428.         ++count;
  429.  
  430. /* Since the inner loop is the same in each case of the switch below */
  431. /* we just define it once for easy modification.                     */
  432. #define COMPUTE_LOOP              {                                  \
  433.         pixel = (image[j1][i1]+image[j1][i1+1]+image[j1+1][i1]+      \
  434.                 image[j1+1][i1+1])/4.0;                              \
  435.         image1[j][i] = bound(0.5 + trans->scale*pixel+trans->offset);\
  436.         }
  437.  
  438.         switch(trans->sym_op) {
  439.            case 0: for (i=trans->rx, i1 = trans->dx; 
  440.                          i<trans->rrx; ++i, i1 += 2)
  441.                    for (j=trans->ry, j1 = trans->dy; 
  442.                          j<trans->rry; ++j, j1 += 2) 
  443.                        COMPUTE_LOOP
  444.                    break;
  445.            case 1: for (j=trans->ry, i1 = trans->dx;
  446.                            j<trans->rry; ++j, i1 += 2)
  447.                    for (i=trans->rrx-1,
  448.                            j1 = trans->dy; i>=(int)trans->rx; --i, j1 += 2) 
  449.                        COMPUTE_LOOP
  450.                    break;
  451.            case 2: for (i=trans->rrx-1, 
  452.                           i1 = trans->dx; i>=(int)trans->rx; --i, i1 += 2)
  453.                    for (j=trans->rry-1,
  454.                            j1 = trans->dy; j>=(int)trans->ry; --j, j1 += 2) 
  455.                        COMPUTE_LOOP
  456.                    break;
  457.            case 3: for (j=trans->rry-1,
  458.                            i1 = trans->dx; j>=(int)trans->ry; --j, i1 += 2)
  459.                    for (i=trans->rx, j1 = trans->dy;
  460.                            i<trans->rrx; ++i, j1 += 2) 
  461.                        COMPUTE_LOOP
  462.                    break;
  463.            case 4: for (j=trans->ry, i1 = trans->dx;
  464.                            j<trans->rry; ++j, i1 += 2)
  465.                    for (i=trans->rx, j1 = trans->dy;
  466.                            i<trans->rrx; ++i, j1 += 2) 
  467.                        COMPUTE_LOOP
  468.                    break;
  469.            case 5: for (i=trans->rx, i1 = trans->dx;
  470.                            i<trans->rrx; ++i, i1 += 2)
  471.                    for (j=trans->rry-1,
  472.                            j1 = trans->dy; j>=(int)trans->ry; --j, j1 += 2) 
  473.                        COMPUTE_LOOP
  474.                    break;
  475.            case 6: for (j=trans->rry-1,
  476.                            i1 = trans->dx; j>=(int)trans->ry; --j, i1 += 2)
  477.                    for (i=trans->rrx-1,
  478.                            j1 = trans->dy; i>=(int)trans->rx; --i, j1 += 2) 
  479.                        COMPUTE_LOOP
  480.                    break;
  481.            case 7: for (i=trans->rrx-1, 
  482.                           i1 = trans->dx; i>=(int)trans->rx; --i, i1 += 2)
  483.                    for (j=trans->ry, j1 = trans->dy; 
  484.                           j<trans->rry; ++j, j1 += 2) 
  485.                        COMPUTE_LOOP
  486.                    break;
  487.         }  
  488.   
  489.     }
  490.     tempimage = image;
  491.     image = image1;
  492.     image1 = tempimage;
  493.  
  494.     printf("\n%d transformations applied.",count);
  495. }
  496.  
  497. /*        This should really be done when they are read in.     */
  498. /* ************************************************************ */
  499. scale_transformations(scalefactor)
  500. double scalefactor;
  501. {
  502.     trans = &transformations;
  503.     while (trans->next != NULL) {
  504.         trans = trans->next;
  505.  
  506.         trans->rrx *= scalefactor;
  507.         trans->rry *= scalefactor;
  508.         trans->rx *= scalefactor;
  509.         trans->ry *= scalefactor;
  510.         trans->dx *= scalefactor;
  511.         trans->dy *= scalefactor;
  512.     }
  513. }
  514.  
  515. /* ************************************************************* */
  516. /* Recursively partition an image, finding the largest contained */
  517. /* square and call read_transformations .                        */
  518. /* ************************************************************* */
  519. partition_image(atx, aty, hsize,vsize )
  520. int atx, aty, hsize,vsize;
  521. {
  522.    int x_exponent,    /* the largest power of 2 image size that fits */
  523.        y_exponent,    /* horizontally or vertically the rectangle.   */
  524.        exponent,      /* The actual size of image that's encoded.    */
  525.        size, 
  526.        depth; 
  527.    
  528.    x_exponent = (int)floor(log((double)hsize)/log(2.0));
  529.    y_exponent = (int)floor(log((double)vsize)/log(2.0));
  530.    
  531.    /* exponent is min of x_ and y_ exponent */
  532.    exponent = (x_exponent > y_exponent ? y_exponent : x_exponent);
  533.    size = 1<<exponent; 
  534.    depth = max_exponent - exponent;
  535.  
  536.    read_transformations(atx,aty,size,size,depth);
  537.  
  538.    if (size != hsize) 
  539.       partition_image(atx+size, aty, hsize-size,vsize );
  540.  
  541.    if (size != vsize) 
  542.       partition_image(atx, aty+size, size,vsize-size );
  543. }        
  544.   
  545. /* ************************************************************* */
  546. /* Scan the image and average the transformation boundaries.     */
  547. /* ************************************************************* */
  548. smooth_image()
  549. {
  550.     IMAGE_TYPE pixel1, pixel2;
  551.     int i,j;
  552.     int w1,w2;
  553.  
  554.     printf("\nPostprocessing Image.");
  555.     trans = &transformations;
  556.     while (trans->next != NULL) {
  557.         trans = trans->next;
  558.         if (trans->rx == 0 || trans->ry == 0) 
  559.             continue;
  560.         
  561.         if (trans->depth == max_part) {
  562.             w1 = 5;
  563.             w2 = 1;
  564.         } else {
  565.             w1 = 2;
  566.             w2 = 1;
  567.         }
  568.  
  569.         for (i=trans->rx; i<trans->rrx; ++i) {
  570.              pixel1 = image[(int)trans->ry][i];
  571.              pixel2 = image[(int)trans->ry-1][i];
  572.              image[(int)trans->ry][i] = (w1*pixel1 + w2*pixel2)/(w1+w2);
  573.              image[(int)trans->ry-1][i] = (w2*pixel1 + w1*pixel2)/(w1+w2);
  574.         }
  575.  
  576.         for (j=trans->ry; j<trans->rry; ++j) {
  577.              pixel1 = image[j][(int)trans->rx];
  578.              pixel2 = image[j][(int)trans->rx-1];
  579.              image[j][(int)trans->rx] = (w1*pixel1 + w2*pixel2)/(w1+w2);
  580.              image[j][(int)trans->rx-1] = (w2*pixel1 + w1*pixel2)/(w1+w2);
  581.         }
  582.     }
  583. }
  584.